CefSharp基于.Net Framework 4.0 框架编译 您所在的位置:网站首页 winform core framework CefSharp基于.Net Framework 4.0 框架编译

CefSharp基于.Net Framework 4.0 框架编译

2023-04-29 08:38| 来源: 网络整理| 查看: 265

CefSharp基于.Net Framework 4.0 框架编译

本次源码使用的是Github上CefSharp官方的79版本源码

准备 IDE

Visual Studio 2017 Enterprise

Environment

Windows10 SDK

VC2013 Redistributale Package x86\x64

组件清单

以下组件按照顺序进行编译最佳

基础层 CefSharp(C#) CefSharp.Core(C++) CefSharp.BrowserSubprocess.Core(C++) CefSharp.BrowserSubprocess(C#) UI层 CefSharp.WinForms(C#) Example

CefSharp.Example

CefSharp.WinForms.Example

开始

建立一个名为CefSharp-DotNet4.0的空的解决方案(下文简称sln哈),咱们就开始吧!

CefSharp

首先把79版本的源码中的CefSharp库加入到sln中,形成如下的结构:

先不将框架切换为4.0尝试编译一下,出现报错提示:

1>------ Rebuild All started: Project: CefSharp, Configuration: Debug x64 ------ 1>CSC : error CS7027: Error signing output with public key from file '..\CefSharp.snk' -- File not found. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

检查79版本的源码发现,需要将CefSharp.snk文件放置到sln根目录下,这里照做,然后编译通过。

接着切换为4.0尝试编译,编译出现大量错误,仔细检查发现有如下几种:

1、CefSharp.Web.JsonString.FromObject函数的参数DataContractJsonSerializerSettings并不存在

原因:4.0还不存在该种形式的调用

解决办法:移除该方法的settings参数,移除DataContractJsonSerializerSettings构造函数的settings参数

2、CefSharp.Internals.ConcurrentMethodRunnerQueue.Enqueue方法中,调用了PropertyInfo.GetValue方法报错

原因:该PropertyInfo.GetValue方法在4.5及以上可以不传入第二个参数object[] index

解决办法:GetValue函数传入第二个参数为null即可

3、CefSharp.SchemeHandler.FolderSchemeHandlerFactory.ISchemeHandlerFactory.Create中WebUtility.UrlDecode报错

原因:该方法是对一般字符串编码为Url的实现,在4.5及以上中才有

解决办法:实现一个相同的功能的方法替换之,因为后续还有些处理转为4.0后的兼容问题的代码,所以本人在CefSharp增加了一个ExHelper命名空间,用于存放后续的扩展处理代码的Helper,这里首先增加一个WebUtilityHelper的处理类,该类有一个静态方法UrlDecode,其实现本人直接拷贝的.NET 4.7.2的实现,代码如下:

namespace CefSharp.ExHelper { /// /// https://referencesource.microsoft.com/#System/net/System/Net/HttpListenerRequest.cs,80a5cbf6a66fa610 /// public class WebUtilityHelper { private int _bufferSize; // Accumulate characters in a special array private int _numChars; private char[] _charBuffer; // Accumulate bytes for decoding into characters in a special array private int _numBytes; private byte[] _byteBuffer; // Encoding to convert chars to bytes private Encoding _encoding; internal WebUtilityHelper(int bufferSize, Encoding encoding) { _bufferSize = bufferSize; _encoding = encoding; _charBuffer = new char[bufferSize]; // byte buffer created on demand } public static string UrlDecode(string encodedValue) { if (encodedValue == null) return null; return UrlDecodeInternal(encodedValue, Encoding.UTF8); } private static string UrlDecodeInternal(string value, Encoding encoding) { if (value == null) { return null; } int count = value.Length; WebUtilityHelper helper = new WebUtilityHelper(count, encoding); // go through the string's chars collapsing %XX and // appending each char as char, with exception of %XX constructs // that are appended as bytes for (int pos = 0; pos < count; pos++) { char ch = value[pos]; if (ch == '+') { ch = ' '; } else if (ch == '%' && pos < count - 2) { int h1 = HexToInt(value[pos + 1]); int h2 = HexToInt(value[pos + 2]); if (h1 >= 0 && h2 >= 0) { // valid 2 hex chars byte b = (byte)((h1


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有